﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GoL
{
	public partial class SettingsMenu : Form
	{
		public Point gridDimension { get; private set; }
		public Int32 cellSize { get; private set; }
		public Int32 cellSpacing { get; private set; }
		public Int32 animateInterval { get; private set; }
		public Color inactiveColor { get; private set; }
		public Color activeColor { get; private set; }
		public Boolean changed { get; private set; }

		public SettingsMenu()
		{
			InitializeComponent();
		}
		public SettingsMenu(Point gridDimension, Int32 cellSize, Int32 cellSpacing, Int32 animateInterval, Color inactiveColor, Color activeColor)
		{
			this.gridDimension = gridDimension;
			this.cellSize = cellSize;
			this.cellSpacing = cellSpacing;
			this.animateInterval = animateInterval;
			this.inactiveColor = inactiveColor;
			this.activeColor = activeColor;
			InitializeComponent();
		}

		private void ColorPanel_MouseClick(object sender, MouseEventArgs e)
		{
			Panel colorPanel = (Panel)sender;
			ColorDialog colorDialog = new ColorDialog();
			colorDialog.SolidColorOnly = true;
			colorDialog.ShowDialog();
			colorPanel.BackColor = colorDialog.Color;
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			changed = false;
			this.Close();
		}

		private void btnSubmit_Click(object sender, EventArgs e)
		{
			gridDimension = new Point(Convert.ToInt32(txtGridX.Text), Convert.ToInt32(txtGridY.Text));
			cellSize = Convert.ToInt32(txtCellSize.Text);
			cellSpacing = Convert.ToInt32(txtCellSpacing.Text);

			if (rbAnimFast.Checked)
				animateInterval = 80;
			if (rbAnimMed.Checked)
				animateInterval = 400;
			if (rbAnimSlow.Checked)
				animateInterval = 1000;

			inactiveColor = pnlInactiveColor.BackColor;
			activeColor = pnlActiveColor.BackColor;
			changed = true;
			this.Close();
		}

		private void txtCellSize_TextChanged(object sender, EventArgs e)
		{
			txtCellSizeAlt.Text = txtCellSize.Text;
		}

		private void numField_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (e.KeyChar < '0' || e.KeyChar > '9')
				e.Handled = true;
		}

		private void SettingsMenu_Load(object sender, EventArgs e)
		{
			txtGridX.Text = gridDimension.X.ToString();
			txtGridY.Text = gridDimension.Y.ToString();
			txtCellSize.Text = cellSize.ToString();
			txtCellSpacing.Text = cellSpacing.ToString();
			pnlInactiveColor.BackColor = inactiveColor;
			pnlActiveColor.BackColor = activeColor;

			rbAnimFast.Checked = animateInterval == 80;
			rbAnimMed.Checked = animateInterval == 400;
			rbAnimSlow.Checked = animateInterval == 1000;
		}
	}
}
